package com.smartstate.dataManagement.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smartstate.dataManagement.dto.EnergyDTO;
import com.smartstate.dataManagement.entity.HalfHourFlowMeterSummaryEntity;
import com.smartstate.dataManagement.entity.HalfHourNaturalGasSummaryEntity;
import com.smartstate.dataManagement.entity.HalfHourPowerMeterSummaryEntity;
import com.smartstate.dataManagement.entity.HalfHourVapourSummaryEntity;
import com.smartstate.dataManagement.vo.HalfHourPowerMeterSummaryEntityVo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface PowerMeterSummaryMapper extends BaseMapper<HalfHourPowerMeterSummaryEntity> {

    @Select("select medium, detailed from ratecalculation where effectiveTime <= #{startTime} order by effectiveTime DESC limit 1")
    Map<String, String> queryRate(@Param("startTime") String startTime);


    @Insert("insert into half_hour_power_meter_summary values(#{id},#{objId},#{meterId},#{startTime},#{endTime},#{createTime}" +
            ",#{detActiveEnergy},#{detReactiveEnergy},#{detApparentEnergy},#{price},#{totalPrice},#{rateType},#{dayStr}" +
            ",#{weekStr},#{monthStr},#{yearStr},#{peekValue},#{flatValue},#{valleyValue})")
    boolean saveMeter( HalfHourPowerMeterSummaryEntity halfHourPowerMeterSummaryEntity);

    //    查询数据能耗数据
    Map queryByDTO(@Param("energyDTO") EnergyDTO energyDTO);

    /**
     * 半小时颗粒度 成本计算
     * @param energyDTO
     * @return
     */
    List<HalfHourPowerMeterSummaryEntity> selectHourPrice(@Param("energyDTO") EnergyDTO energyDTO);

    /**
     * 日 周 月 年 颗粒度 成本计算
     * @param energyDTO
     * @return
     */
    List<HalfHourPowerMeterSummaryEntity> selectDatePrice(@Param("energyDTO") EnergyDTO energyDTO);

    /**
     * 环比
     */
    List<HalfHourPowerMeterSummaryEntityVo>selectLinkRelativeRatio(@Param("energyDTO") EnergyDTO energyDTO);

    /**
     * 插入水表数据
     * @param halfHourFlowMeterSummaryEntity
     * @return
     */
    boolean saveWater(HalfHourFlowMeterSummaryEntity halfHourFlowMeterSummaryEntity);

    /**
     * 插入天然气数据
     * @param halfHourNaturalGasSummaryEntity
     * @return
     */
    boolean saveNaturalGas(HalfHourNaturalGasSummaryEntity halfHourNaturalGasSummaryEntity);

    /**
     * 插入水蒸气数据
     * @param halfHourVapourSummaryEntity
     */
    void saveVapour(HalfHourVapourSummaryEntity halfHourVapourSummaryEntity);

    /**
     * 获取时间颗粒度为半小时的总数
     * @param energyDTO
     * @return
     */

    Long queryHourTotal(@Param("energyDTO") EnergyDTO energyDTO);

    /**
     * 查询偏移的结束时间
     * @param offset
     * @return
     */
    String queryOffSetEndTime(@Param("energyDTO") EnergyDTO energyDTO, long offset);

    /**
     * 获取除半小时的其他时间颗粒度，分页查询
     * @param energyDTO
     * @return
     */
    List<HalfHourPowerMeterSummaryEntity> selectDatePricePage(@Param("energyDTO") EnergyDTO energyDTO);

    /**
     * 获取除半小时的其他时间颗粒度的总数
     * @param energyDTO
     * @return
     */
    long queryDateTotal(@Param("energyDTO") EnergyDTO energyDTO);


}
